import path from 'path'
import i18n from '@/i18n'
export const generateRoutes = (routes, basePath = '/', prefixTitle = []) => {
  let res = []
  for (const route of routes) {
    const item = {
      path: path.resolve(basePath, route.path),
      title: [
        ...prefixTitle
      ]
    }
    // 动态路由不允许被检索
    const re = /.*\/:.*/
    if (route.meta && route.meta.title && !re.exec(route.path)) {
      const i18nTitle = i18n.global.t(`route.${route.meta.title}`)
      item.title.push(i18nTitle)
      res.push(item)
    }
    if (route.children) {
      const tempRoute = generateRoutes(route.children, item.path, item.title)
      if (tempRoute.length >= 1) {
        res = [...res, ...tempRoute]
      }
    }
  }
  return res
}
